package com.changgou.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.service.ESManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ProjectName: changgou_parent
 * @Package: com.changgou.controller
 * @ClassName: ESManagerController
 * @Author: 孙明田
 * @Description: 搜索控制类
 * @Date: 2020/6/19 15:48
 * @Version: 1.0
 */
@RestController
@RequestMapping("/manager")
public class ESManagerController {

    @Autowired
    private ESManagerService esManagerService;


    /**
     * 创建索引结构
     *
     * @return
     */
    @GetMapping("/create")
    public Result create() {
        esManagerService.createIndexAndMapping();
        return new Result(true, StatusCode.OK, "创建索引库成功");
    }


    /**
     * 将所有数据导入es
     *
     * @return
     */
    @GetMapping("/importAll")
    public Result importAll() {
        esManagerService.importAll();
        return new Result(true, StatusCode.OK, "数据导入成功");
    }
}
